% This function recover the signal support (CTF) from the sample sequences.
% Expanding the inputs in factor q is performed if q>1
%ExSamples, ExTimeAxis
function [Support  Success A] = RecoverSupport(Signal, MWC, Samples, Time_Axis, refSupprort)

%%  Get relevant parameters
fmax = getfield(Signal.Structure, 'fmax');
N=getfield(Signal.Structure, 'N');
fnyq = 2*fmax;
M = getfield(MWC, 'M');
m = getfield(MWC, 'm');
fp =getfield(MWC, 'fp');
Ts = getfield(MWC, 'Ts');
fs = 1/Ts;
L =getfield(MWC, 'L');
if (mod(L,2)==0)
    L=L+1;
end   % L is the number of specturm slices, namely the length of z[n]

%% Initialize Recovery Parameters
% compute the sensing matrix
[ A ] = computeSensingMatrix( MWC);

C = A;
y = Samples;
% size(y)
%% RUN SBR
if(strcmp(MWC.SBR, 'SBR2'))
    
    %%
    SBR_COUNTER = 0;
    LamdaTau = fp/2;
    eps = fp/20;  %999 what should we put here, really?
    spark = 2 * N;
    
    [ Support , ~ ] = sbr2( y,N,C,LamdaTau,eps,spark,Time_Axis,MWC.fp ); 
    
    % Decide on success
    if (is_contained(refSupprort,Support)  && (rank(C(:,Support)) == length(Support)))
        Success= 1;
    else
        Success = 0;
    end
    %%
elseif(strcmp(MWC.SBR, 'SBR4'))
    [ Support Success ] = sbr4( y,N,C,refSupprort ); 
    
elseif(strcmp(MWC.SBR, 'SBRspecial'))
    [ Support Success ] = sbrSpecial(y,N,C,refSupprort);
    
end


    
end


